import React, { PureComponent } from 'react'
import { View, Text, TextInput } from 'react-native'
import { Button, Toast, Result } from 'antd-mobile'
import color from '../../utils/color'
import screen from '../../utils/screen'
import { BackIcon, PullView } from '../../widgets'
import {connect} from 'react-redux'
import { createAction, NavigationActions } from '../../utils'

@connect(({ consultant, loading }) => ({ ...consultant, isLoading: loading.models.consultant }))
export default class extends PureComponent {
  static navigationOptions = ({ navigation }) => ({
    title: '发布留言',
    headerStyle: {
      backgroundColor: color.theme,
      elevation: 0,
      shadowOpacity: 0,
    },
    headerTitleStyle: {
      color: 'white',
      fontSize: screen.pxToDp(30),
      marginLeft: screen.pxToDp(26),
    },
    headerLeft: ( <BackIcon backInvoke={() => { navigation.goBack(null) }}/>),
  })
  constructor(props) {
    super(props)
    this.state = {
      message: '',
    }
  }

  componentWillMount() {
    this.props.dispatch(createAction("consultant/resetStatus")({}))
  }

  invokeSubmit = () => {
    const params = this.props.navigation.state.params || {};
    this.props.dispatch(createAction("consultant/submitMessage")({
      type: params.type || 0,
      projectId: params.projectId || '',
      content: this.state.message,
    }))
  }
  render() {
    const { submitResultState} = this.props
    if(submitResultState == 1) {
      return (
        <Result
          title="留言成功"
          message="恭喜您，留言成功"
        />
      )
    } else {
      return (
        <View>
          <TextInput
            value={this.state.message}
            onChangeText={(v) => {
              this.setState({message: v})
            }}
            placeholder="请在此区域输入您的留言"
            multiline
            autoFocus
            underlineColorAndroid="transparent"
            style={{textAlignVertical: 'top',height: screen.pxToDp(400), borderWidth: 0, borderColor: 'white'}}
          />
          <Button onClick={this.invokeSubmit}>提交</Button>
        </View>
      )
    }
  }
}
